package com.example.supplychainbackend.entity.logistic;

import com.example.supplychainbackend.tool.DateTimeUtils;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicInteger;

@Entity
@Table(name = "foreign_logistic")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ForeignLogisticEntity {
    @Id
    String	id;

    String	productName;
    String	po;
    String	no;
    String	planShipNum;
    String	version;
    String	boxNum;
    String	planShipAmount;
    String	unitPrice;
    String	shipAmount;
    String	shipNum;
    String	shipDate;
    String	bl_no;
    String	invoice_NO;
    String	consignArrDate;
    String	consignArrNum;
    String	consignArrAmount;
    String	consignUseDate;
    String	consignUseNum;
    String	consign_PO_NO;
    String	consignUseAmount;
    String	consignInvoice_NO;
    String	consignInvoiceAmount;
    String	consignInvoiceDate;
    String	consignPayDate;
    String	state;

    String	userName;
    String	enterpriseName;
    Boolean	onChain;
    String	transactionId;
    String	commitTime;
    String	userId;
    String	enterpriseId;

    @Transient
    private static final AtomicInteger counter = new AtomicInteger(1);

    @PrePersist
    public void generateId() {
        if (id == null || id.equals("")) {
            id = String.format("%s%s%04d",
                    "COSCO", DateTimeUtils.getCurrentDateForID(), counter.getAndIncrement());
        }
    }
}

